-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alternatives for serving plugin #99
Conversation
Great work! I like this. Make it ready for review? :) |
grpcplugin.Serve(pluginOpts) | ||
} | ||
|
||
type Plugin interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments please for these exported interfaces and the types that Follow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah good point, but still a draft. So only consider the concept/examples
@@ -0,0 +1,85 @@ | |||
package datasource |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Package datasource ....
The idea would be to stick with example 1 or example 2, not both. Same changes would be needed for both app and transform. Or keep it as is. |
OrgID int64 | ||
DataSourceConfig backend.DataSourceConfig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only OrgID and DataSourceConfig exposed here compared to regular CallResourceRequest
which includes both PluginConfig and DataSourceConfig.
Helps not confusing plugin developer to use PluginConfig (currently only app plugins) when should be using DataSourceConfig.
type CallDataSourceResourceHandlerFunc func(ctx context.Context, req *CallDataSourceResourceRequest, sender backend.CallResourceResponseSender) error | ||
|
||
func (fn CallDataSourceResourceHandlerFunc) CallResource(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error { | ||
return fn(ctx, &CallDataSourceResourceRequest{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not super found of this mapping back and forth, but removes the need of implementing yet another interface in resource and httpadapter packages.
type Plugin interface { | ||
CheckDataSourceHealthHandler | ||
CallDataSourceResourceHandler | ||
backend.QueryDataHandler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be correct, this one should probably have a new interface in this package as well to only include DataSourceConfig in request and not PluginConfig.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be an interface similar to https://github.com/grafana/grafana/blob/master/pkg/tsdb/query_endpoint.go#L11, basically using similar DataSource
model struct.
Trying to think through using interfaces, and non-breaking upgrades. For example with the
However, at step 3, wouldn't the plugin author get something like "MyDataSource is not a datasource.Plugin, missing QuerySloth(...) ...` Edit: Looking at "Interfaces" section of https://about.sourcegraph.com/go/gophercon-2019-detecting-incompatible-api-changes |
please please please please look at #105 and see if this is related. Having an instance concept encapsulated by the API would be a really nice starting place |
@marefr lets close this? |
Suggestion to make it easier for a plugin developer to understand what interfaces they need to implement for a certain plugin type (datasource/app) and what interfaces we want to enforce a certain plugin to implement I started to think about using a "base struct" for default implementations. Struggled a lot with this "base struct" without being satisfied until I came to the conclusion that in general composition in favorable over inheritance.
In addition #96 suggested adding a new CheckDataSourceHealth to the existing
QueryDataHandler
to try and overcome the "weirdness" of having both a PluginConfig and a DataSourceConfig.I think having a single interface that must be implemented per plugin type is desirable.
Current way of serving a plugin
https://github.com/grafana/google-sheets-datasource/blob/1e50d97f3bfd40870997039b17c0c8c901f8fbf8/pkg/main.go#L11-L27
Weakness with current approach is that there's nothing enforcing you to implement one interface, instead there's 4 different interfaces in
backend.ServeOpts
and it's probably not clear from a plugin developer perspective which ones I need/should implement.Example 1
Must implement
backend.DataSourcePlugin
interface to be able to serve data source plugin.Example 2
Using new datasource package with explicit
datasource.Plugin
interface. Must implementdatasource.Plugin
interface to be able to serve data source plugin.